// Copyright (c) 2010, Peng Long, NARI-TECH

#include <iostream>
#include <stdio.h>


using namespace std;

template <typename T>
class CTSqrt
{
	public:
	double Solve(const T sqnum,const T init_val_0);
	int Set(int maxn,T e);
	private:
	T sqrt_num;
	double init_val_1;
	long int max_iter_num;
	long int iter_num;
	double eps;
};

template <typename T>
double CTSqrt<T>::Solve(const T sqnum,const T init_val_0)
{

    sqrt_num=sqnum;
    cout<<max_iter_num<<endl;
    cout<<eps<<endl;
    T init_temp=init_val_0;
    for(iter_num=0;iter_num<max_iter_num;iter_num++)
    {
      init_val_1=(init_temp+sqrt_num/init_temp)/2;
        double temp = init_val_1-init_temp;
        if((temp<eps)&&(temp>-eps))
        {
             break;
        }
        init_temp=init_val_1;
        cout<<"no."<<iter_num<<" is "<<init_val_1<<endl;
    }
    if(iter_num==max_iter_num)
    {
        cout<<"max_iter_num!!"<<endl;
    }

    return init_val_1;
}

template <typename T>
int CTSqrt<T>::Set(int maxn=50,T e=1e-5)
{
    max_iter_num=maxn;
    eps=e;
}

class Secs
{
  public:
    int isright();
    double solve();
    int input();
  private:
    long year;
    long month;
    long day;
};

double Secs::solve()
{
    const double day_sec = 24*3600;
    const double year_day = 365*100+24;
    double sec = day_sec*year_day;

    if( !(year%100) && !(year%400) && month<3)
        sec+=day_sec;
    else if( !(year%100) && (year%400==300) && month>2)
        sec+=day_sec;
    return sec;
}
int Secs::input()
{
    cout<<"!!your birthday!!"<<endl;
    cout<<"year:";
    cin>>year;
    cout<<"month:";
    cin>>month;
    cout<<"day:";
    cin>>day;

}
int Secs::isright()
{
    int month_day[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
    if( (!(year%100) && !(year%400)) || (year%100 && !(year%4)) )
        month_day[1]++;
    if(month>12 || month<1)
        return -1;
    if(day>month_day[month-1] || day<1)
        return -1;
}
int main()
{
    long y,m,d;
    double sec ;
    CTSqrt <double> SecSqrt;
    int count=1;
    int max_iter;
    double e;
    double test;
    Secs birthday;

    do
    {
    birthday.input();
    }while(birthday.isright()<0);
    sec = birthday.solve();

    cout<<sec<<endl;
    cout<<"set max_iter_num and eps?(y/n):";
    char ch ;
    cin>>ch;
    if(ch=='y')
    {
        cout<<"max_iter:";
        cin>>max_iter;
        cout<<"eps:";
        cin>>e;
        SecSqrt.Set(max_iter,e);
    }
    else
        SecSqrt.Set();

    cout<<"get init num: ";
    cin>>test;
    do
    {

        cout<<endl<<"this the no."<<count<<" Sqrt!"<<endl;
        count++;
    }while((sec=SecSqrt.Solve(sec,test))>2);

    return 0;
}
